home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / NRPAS13 / TRIDAG.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-29  |  663b  |  24 lines

  1. PROCEDURE tridag(a,b,c,r: glnarray; VAR u: glnarray; n: integer);
  2. (* Programs using routine TRIDAG should define the type
  3. TYPE
  4.    glnarray = ARRAY [1..n] OF real;
  5. in the main routine. *)
  6. VAR
  7.    j: integer;
  8.    bet: real;
  9.    gam: glnarray;
  10. BEGIN
  11.    IF (b[1] = 0.0) THEN BEGIN writeln('pause 1 in TRIDAG'); readln END;
  12.    bet := b[1];
  13.    u[1] := r[1]/bet;
  14.    FOR j := 2 TO n DO BEGIN
  15.       gam[j] := c[j-1]/bet;
  16.       bet := b[j]-a[j]*gam[j];
  17.       IF (bet = 0.0) THEN BEGIN writeln('pause 2 in TRIDAG'); readln END;
  18.       u[j] := (r[j]-a[j]*u[j-1])/bet
  19.    END;
  20.    FOR j := n-1 DOWNTO 1 DO BEGIN
  21.       u[j] := u[j]-gam[j+1]*u[j+1]
  22.    END
  23. END;
  24.